package com.zengqingfa.designpattern.create.prototype.shallow;

/**
 *
 * @fileName: Client
 * @author: zengqf3
 * @date: 2021-4-23 17:35
 * @description:
 */
public class Client {

    public static void main(String[] args) throws Exception {
        Owner owner = new Owner("aa");
        Shape shape = new Shape("bb", owner);
        Shape clone = (Shape) shape.clone();
        /**
         * clone=Shape{name='bb', owner=Owner{name='aa'}com.zengqingfa.designpattern.create.prototype.shallow.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.shallow.Shape@6f496d9f
         * shape=Shape{name='bb', owner=Owner{name='aa'}com.zengqingfa.designpattern.create.prototype.shallow.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.shallow.Shape@723279cf
         * 生成了不同的对象，owner是同一个
         */
        System.out.println("clone=" + clone);
        System.out.println("shape=" + shape);


        //修改owner
        /**
         * shape=Shape{name='bb', owner=Owner{name='cc'}com.zengqingfa.designpattern.create.prototype.shallow.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.shallow.Shape@723279cf
         * clone=Shape{name='bb', owner=Owner{name='cc'}com.zengqingfa.designpattern.create.prototype.shallow.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.shallow.Shape@6f496d9f
         * 两个owner都改变了,是同一个对象
         */
        owner.setName("cc");
        System.out.println("shape=" + shape);
        System.out.println("clone=" + clone);
    }
}
